package com.zxw.user.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zxw.common.core.base.res.BaseRes;
import com.zxw.user.api.RoleMenuAPI;
import com.zxw.user.domain.dto.LoginRouteDTO;
import com.zxw.user.domain.entity.RoleButton;
import com.zxw.user.domain.vo.RoleButtonUpdateVO;
import com.zxw.user.domain.vo.RoleMenuUpadteVO;
import com.zxw.user.service.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-02-27
 */
@Api("角色菜单")
@RestController
@RequestMapping("/role-menu")
@RequiredArgsConstructor
public class RoleMenuController implements RoleMenuAPI {

    private final RoleMenuService roleMenuService;

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("获取当前登陆用户公司拥有的菜单")
    @GetMapping("/login-route-menu")
    public BaseRes<List<LoginRouteDTO>> getLoginRouteMenu() {
        List<LoginRouteDTO> loginRouteDTOList = roleMenuService.getLoginRouteMenu();
        return BaseRes.ok(loginRouteDTOList);
    }


    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("获取角色对应的菜单ids")
    @GetMapping("/role-menu_ids/{role_id}")
    public BaseRes<List<Long>> getMenuIdsByRoleId(@PathVariable(value = "role_id") Long roleId) {
        List<Long> menuIds = roleMenuService.getMenuIdsByRoleId(roleId);
        return BaseRes.ok(menuIds);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("批量更新角色权限")
    @PutMapping("/update/{roleId}")
    public BaseRes<RoleButton> update(@PathVariable Long roleId, @RequestBody RoleMenuUpadteVO roleMenuUpadteVO) {
        roleMenuUpadteVO.setRoleId(roleId);
        roleMenuService.update(roleMenuUpadteVO);
        return BaseRes.okAdd();
    }
}
